home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / twinopus / dopus / redo_names.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1995-07-04  |  2.6 KB  |  109 lines

  1. /*
  2.  
  3.    Convert old Cache Filenames to the new format of Cache Filenames...
  4.  
  5.    - Directory OPus must be running in the background for this routine to work !!
  6.  
  7. */
  8.  
  9. /* trace ?R */
  10.  
  11. say "Twin Opus Cache Filename Converter."
  12.  
  13. if ~exists("TwinDirs:") then do
  14.    say "you must have **TwinDirs:** assigned before you call this program"
  15.    exit
  16. end
  17.  
  18. if exists("TwinDirs:Redo_Complete") then do
  19.    say "Conversion already done on this Dir !!"
  20.    exit
  21. end
  22.  
  23. /* list the files present into a file
  24.     - last line of the file t:CDirs, contains verboce info */
  25. say "Reading in Dir of Cached Dirs..."
  26. address command "list quick files TwinDirs: >t:CDirs"
  27.  
  28. /* convert the filenames */
  29. say "Now Converting the Filenames..."
  30. say " This could take a while if you have many Cached Dirs..."
  31.  
  32. open(Files, "t:CDirs", Read)
  33.  
  34. Cont  = True
  35. Count = 0
  36. do while Cont = True
  37.    OldName = readln(files)
  38.    if left(OldName,1) > 9 then do
  39.       Count = Count + 1
  40.       address command "echo . noline"
  41.  
  42.       NewName  = 'twindirs:' || ConvertFilename(OldName)
  43.       FOldName = 'twindirs:' || OldName
  44.       if FOldName ~= NewName then do
  45.          /* not work !!addrexx command "rename " FOldName NewName */
  46.  
  47.          /* method:= read file, create the new file, and copy the data across */
  48.          open(Input,  FOldName, read )
  49.          open(Output, NewName , write)
  50.          do until EOF(Input)
  51.             line = readln(Input)
  52.             writeln(Output, line)
  53.          end
  54.          close(Input)
  55.          close(Output)
  56.          address command "delete " Quote(FOldName) " >NIL:"
  57.       end
  58.    end
  59.    else
  60.       Cont = False
  61. end
  62.  
  63. /* write a file saying that these dirs have already been processed */
  64. open(temp, "TwinDirs:Redo_Complete", Write)
  65. writeln(temp, "Dirs already Processed !!")
  66. close(temp)
  67.  
  68. /* all done */
  69. say "  "
  70. say "  "
  71. say "All Done... I processed " Count " conversions !!"
  72.  
  73. exit
  74.  
  75. /*---------------------------------------------------------------------------*/
  76.  
  77. /* convert a file name from 'df0=ray\was\here to  -> `d0=ry\ws\he
  78.                               (old name)             (new cache filename)*/
  79. ConvertFilename: procedure
  80.  
  81.    parse arg Dev '=' Path
  82.  
  83.    t2 = ''
  84.    Convert = ''
  85.    do until (t2 = '')
  86.        parse var Path t1 '\' t2
  87.        Path = t2
  88.        if t2 ~= '' then
  89.          end = '\'
  90.        else
  91.          end = ''
  92.        Convert = Convert || left(t1,1) || right(t1,1) || end
  93.    end
  94.  
  95.    if left(Convert,1) = ' ' then
  96.       Convert = ''
  97.  
  98.    out = Dev || '=' || Convert
  99.  
  100. return out
  101.  
  102. /*--------------------------------------------------------------------------*/
  103.  
  104. Quote: procedure /* add quotes to string */
  105.  
  106.    parse arg string
  107.  
  108. return '"'||string||'"'
  109.